//
//  SearchWordsModel.m
//  AffectionBee
//
//  Created by 王炯 on 16/8/20.
//  Copyright © 2016年 chivalrous. All rights reserved.
//

#import "SearchWordsModel.h"
#import "NetworkTool.h"


@implementation SearchWordsModel




+(void)GetSearchWordsSucess:(void (^)(NSArray<NSString *> *))successBlock Error:(void (^)())errorBlock
{
    
    //(2)url
    NSString *urlString = @"http://iosapi.itcast.cn/loveBeen/search.json.php";
    
    //(3)参数
    NSDictionary *param = @{@"call":@6};
    
    
    //(4)POST方式请求数据
    [[NetworkTool sharedManager] oauthLoadDataWithNetworkToolType:NetworkToolTypePOST UrlString:urlString parameters:param SuccessBlock:^(NSDictionary *responseObject) {
        
        
        //(0)取验证码code
        NSNumber *codeNum = responseObject[@"code"];
        
        NSInteger code = [codeNum integerValue];
        
        
        //(1)返回data字典
        NSDictionary *dataDict = responseObject[@"data"];
        
        
        //(2)返回data字典中的icons数组
        if (dataDict&& code == 0)
        {
            
            //取数据
            NSArray *strArray = dataDict[@"hotquery"];
            
            
            //(6)调用block返回模型数组
            if (successBlock)
            {
                successBlock(strArray);
            }
        }
        else
        {
            //调用错的block
            if (errorBlock)
            {
                errorBlock();
            }
        }
        
    } failure:^(NSError *error) {
        
        
        //调用错的block
        if (errorBlock)
        {
            errorBlock();
        }
        
    }];
}

@end
